﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace CMS
{
    [Serializable]
    public class Pages
    {
        public long? ADM_ID { get; set; }
        public long? PAG_ID { get; set; }
        public string PAG_TITLE { get; set; }
        public string PAG_CONTENT { get; set; }
        public string PAG_KEYWORDS { get; set; }
        public string PAG_METATAGS { get; set; }
        public Boolean? PAG_VISIBLE { get; set; }

        #region Constructors
        /// <summary>
        /// Creates a new instance of an Page object.
        /// </summary>
        public Pages() : this(null) { }

        /// <summary>
        /// Creates a new instance of an Page object.
        /// </summary>
        public Pages(long? id)
        {
            PAG_ID = id;
        }
        #endregion

        /// <summary>
        /// Returns a list of Pages.
        /// </summary>
        public static List<CMS.Pages> GetPages(Int64? ADM_ID, Int64? PAG_ID, String PAG_TITLE, String PAG_CONTENT, String PAG_KEYWORDS, String PAG_METATAGS, Boolean? PAG_VISIBLE)
        {
            DataTable StoredProcedureTablePages = CMS.StoredProcedureValues.VW_Pages(ADM_ID, PAG_ID, PAG_TITLE, PAG_CONTENT, PAG_KEYWORDS, PAG_METATAGS, PAG_VISIBLE);
            return GetListPages(StoredProcedureTablePages);
        }

        /// <summary>
        /// Converts a DataTable into a list of Pages.
        /// </summary>
        public static List<CMS.Pages> GetListPages(DataTable StoredProcedureTable)
        {
            List<CMS.Pages> OutPages = new List<CMS.Pages>();

            for (int i = 0; i < StoredProcedureTable.Rows.Count; i++)
            {
                CMS.Pages Pages = new CMS.Pages();
                DataRow Row = StoredProcedureTable.Rows[i];

                Pages.PAG_ID = Convert.ToInt64((Row["PAG_ID"]));
                Pages.ADM_ID = Convert.ToInt64((Row["ADM_ID"]));
                Pages.PAG_CONTENT = Row["PAG_CONTENT"].ToString();
                Pages.PAG_TITLE = Row["PAG_TITLE"].ToString();
                Pages.PAG_KEYWORDS = Row["PAG_KEYWORDS"].ToString();
                Pages.PAG_METATAGS = Row["PAG_METATAGS"].ToString();
                Pages.PAG_VISIBLE = CMS.Functions.NullableBoolean(Row["PAG_VISIBLE"]);

                OutPages.Add(Pages);
            }

            return OutPages;
        }
    }
}